package com.hjh.demo.websocket.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;

import com.hjh.demo.websocket.entity.ClientMessage;
import com.hjh.demo.websocket.entity.ServerMessage;

/**
 * 
 * @ClassName: WebSocketAction
 * @Description: websocket控制层
 * @author cheng
 * @date 2017年9月27日 下午4:20:58
 */
@Controller
public class WebSocketAction {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@MessageMapping("/sendTest")
	@SendTo("/topic/subscribeTest")
	public ServerMessage sendDemo(ClientMessage message) {
		logger.info("接收到了信息" + message.getName());
		return new ServerMessage("你发送的消息为:hjh_" + message.getName());
	}

	@SubscribeMapping("/subscribeTest")
	public ServerMessage sub() {
		logger.info("XXX用户订阅了我。。。");
		return new ServerMessage("感谢你订阅了我。。。");
	}
}
